//
//  TravelTableViewCell.m
//  HappinessTrip
//
//  Created by dllo on 15/10/7.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "TravelTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Fit.h"

@implementation TravelTableViewCell
-(void)dealloc
{
    [_pictureImageView release];
    [_blackImageView release];
    [_titleLabel release];
    [_timeLabel release];
    [_whereLabel release];
    [_userImageView release];
    [_userLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}
-(void)createViews
{
    _pictureImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_pictureImageView];
    [_pictureImageView release];
    _blackImageView = [[UIImageView alloc]init];
    [_pictureImageView addSubview:_blackImageView];
    [_blackImageView release];
    _titleLabel = [[UILabel alloc]init];
    [_pictureImageView addSubview:_titleLabel];
    [_titleLabel release];
    _timeLabel = [[UILabel alloc]init];
    [_pictureImageView addSubview:_timeLabel];
    [_timeLabel release];
    _whereLabel = [[UILabel alloc]init];
    [_pictureImageView addSubview:_whereLabel];
    [_whereLabel release];
    _userImageView = [[UIImageView alloc]init];
    [_pictureImageView addSubview:_userImageView];
    [_userImageView release];
    _userLabel = [[UILabel alloc]init];
    [_pictureImageView addSubview:_userLabel];
    [_userLabel release];
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _pictureImageView.frame = CGRectMake(10 * W, 5 * H, self.contentView.frame.size.width - 20 * W, self.contentView.frame.size.height - 10 * H);
    _blackImageView.frame = CGRectMake(0, 0, _pictureImageView.frame.size.width, _pictureImageView.frame.size.height);
    _titleLabel.frame = CGRectMake(20 * W, 20 * H, _pictureImageView.frame.size.width - 40 * W, 40 * H);
    _timeLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 10 * H, _titleLabel.frame.size.width, 10 * H);
    _whereLabel.frame = CGRectMake(_timeLabel.frame.origin.x, _timeLabel.frame.origin.y + _timeLabel.frame.size.height + 5 * H, _timeLabel.frame.size.width, _timeLabel.frame.size.height);
    _userImageView.frame = CGRectMake(_titleLabel.frame.origin.x, 150 * H, 30 * W, 30 * W);
    _userLabel.frame = CGRectMake(_userImageView.frame.origin.x + _userImageView.frame.size.width + 10 * W, _userImageView.frame.origin.y + 5 * H, 200 * W, 20 * H);
}
-(void)setAllData:(AllData *)allData
{
    if (_allData != allData) {
        [_allData release];
        _allData = [allData retain];
    }

    [_pictureImageView sd_setImageWithURL:[NSURL URLWithString: _allData.cover_image] placeholderImage:[UIImage imageNamed:@"dengdai"]];
    _pictureImageView.layer.cornerRadius = 5;
    _pictureImageView.layer.masksToBounds = YES;
    _blackImageView.backgroundColor = [UIColor blackColor];
    _blackImageView.alpha = .2;
    _blackImageView.layer.cornerRadius = 5;
    _blackImageView.layer.masksToBounds = YES;
    _titleLabel.text = _allData.name;
    _titleLabel.textColor = [UIColor whiteColor];
    _timeLabel.text = [NSString stringWithFormat:@"%@  %@天  %@ 次浏览", _allData.first_day, _allData.day_count, _allData.view_count];
    _timeLabel.textColor = [UIColor whiteColor];
    _timeLabel.font = [UIFont systemFontOfSize:13];
    _whereLabel.text = [NSString stringWithFormat:@"%@", _allData.popular_place_str];
    _whereLabel.textColor = [UIColor whiteColor];
    _whereLabel.font = [UIFont systemFontOfSize:13];
    [_userImageView sd_setImageWithURL:[NSURL URLWithString:[_allData.user objectForKey:@"avatar_s"]] placeholderImage:[UIImage imageNamed:@"dengdai"]];
    _userImageView.layer.cornerRadius = _userImageView.frame.size.width / 2;
    _userImageView.layer.masksToBounds = YES;
    _userLabel.text = [_allData.user objectForKey:@"name"];
    _userLabel.textColor = [UIColor whiteColor];
    _userLabel.font = [UIFont systemFontOfSize:15];
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
